package com.yonyou.le.unattended.util;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.yonyou.tool.servlet.ArgInfo;
import com.yonyou.tool.servlet.DefaultType;
import com.yonyou.tool.servlet.DefaultValue;
import com.yonyou.tool.servlet.EXEContextForLE;
import com.yonyou.tool.servlet.ServiceInfo;

/**
 * 访问LE接口
 */
public class CalServletForLE {

	/**
	 * 作业点接口名
	 */
	private static String op_interfaceName = "nc.itf.levm.operatpoint.IOperatpointQueryService";
	/**
	 * 查询作业点方法名
	 */
	private static String opquery_method_name = "queryByPKs";
	/**
	 * 提供设备分类，设备信息，作业点信息和适配器信息的远程接口名
	 */
	private static String delivery_interfaceName = "nc.pubitf.levm.delivery.ILEDeliveryQueryService";
	/**
	 * 查询作业点方法名
	 */
	private static String delivery_query_method_name = "queryDeliveryParam";
	
	/**
	 * 获取作业点接口context
	 * @return
	 */
	public static EXEContextForLE getMonitorPointContext(String pks[]) {
		ServiceInfo info = new ServiceInfo();
		info.setServiceClassName(op_interfaceName);
		info.setServiceMethodName(opquery_method_name);
		ArgInfo[] infos = new ArgInfo[1];
		
		ArgInfo info1 = new ArgInfo();		
		DefaultType argType1 = new DefaultType();
		argType1.setBody(String.class.getName());		
		DefaultValue argValue1 = new DefaultValue();
		argValue1.setBody(pks);
		info1.setArgType(argType1);
		info1.setArgValue(argValue1);
		info1.setArray(true);
		
		infos[0] = info1;
		info.setServiceMethodArgInfo(infos);
		
		return getContextForNC(info);
	}
	
	/**
	 * 返回设备分类，设备信息，作业点信息和适配器信息接口的context
	 * @return
	 */
	public static EXEContextForLE getDeliveryQueryContext() {
		ServiceInfo info = new ServiceInfo();
		info.setServiceClassName(delivery_interfaceName);
		info.setServiceMethodName(delivery_query_method_name);
		return getContextForNC(info);
	}
	/**
	 * NC 查询对象
	 * 
	 * @param clientParamVO
	 * @param serviceInfo
	 * @return
	 */
	private static EXEContextForLE getContextForNC(
			 ServiceInfo serviceInfo) {
		WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
		EXEContextForLE contextForNC = (EXEContextForLE) context.getBean("EXEContextForLE");
		contextForNC.setServiceInfo(serviceInfo);
		return contextForNC;
	}

}
